import {
    BaseController,
    BeanFactory,
    Controller,
    DataType,
    GetMapping,
    PostMapping,
    Resource,
    Result
} from "csap-typescript-vue2/lib";
import {ApiDocService} from "@/api/service/ApiDocService";
import {ApidocModel, ApidocResultModel, ApidocSearchModel, PushSuccess} from "@/api/model/ApidocModel";
import {AxiosPromise} from "axios";

/**
 * 文档信息
 */
@Controller("apiDoc")
export class ApidocController extends BaseController<ApiDocService, ApidocModel, ApidocSearchModel, ApidocResultModel, number> implements BeanFactory {
    @Resource()
    apiDocService: ApiDocService;

    getService(): ApiDocService {
        return this.apiDocService;
    }

    getFormValidate(): Array<Function | ApidocModel> {
        return [ApidocModel];
    }

    @PostMapping("flushDoc")
    flushDoc(docId: Array<number>): AxiosPromise<Result<boolean>> {
        return this.getService().flushDoc(this.request(docId))
    }

    @PostMapping("publishDoc", {dataType: DataType.PARAMS})
    publishDoc(id: number): AxiosPromise<Result<string>> {
        return this.getService().publishDoc(this.request<any>({id: id}))
    }

    @GetMapping("publishSuccess")
    publishSuccess(id: string): AxiosPromise<Result<PushSuccess>> {
        return this.getService().publishSuccess(this.request<any>({id: id}))
    }
}
